﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace WinformPrint
{
    public class dbHelper
    {
        public static DataTable GetDataBySQLNew(string database, string sql)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            string strServer = "Server=10.6.191.23; DataBase=McsDW; user id=sqluser; password=Pass@word;";
            if (database.Equals("McsDW"))
            {
                strServer = "Server=10.6.191.23; DataBase=McsDW; user id=sqluser; password=Pass@word;";
            }
            else if (database.Equals("McsSP"))
            {
                strServer = "Server=10.6.191.23; DataBase=McsSP; user id=sqluser; password=Pass@word;";
            }
            else if (database.Equals("CJWSJY_BeOfficeAuto"))
            {
                strServer = "Server=10.6.191.23; DataBase=CJWSJY_BeOfficeAuto; user id=sqluser; password=Pass@word;";
            }
            else if (database.Equals("FOOD"))
            {
                strServer = "Server=10.6.189.4; DataBase=master; user id=sa; password=Pass@word;";
            }
            using (System.Data.SqlClient.SqlConnection SqlCnn = new System.Data.SqlClient.SqlConnection(strServer))
            {
                SqlCnn.Open();
                System.Data.SqlClient.SqlDataAdapter SqlDa = new System.Data.SqlClient.SqlDataAdapter(sql, SqlCnn);
                System.Data.DataSet DS = new DataSet();
                SqlDa.Fill(DS);
                SqlDa.Dispose();
                SqlCnn.Close();
                if (DS == null || DS.Tables == null || DS.Tables.Count < 1)
                    return null;
                dt = DS.Tables[0];
            }
            return dt;
        }
    }
}
